/*
Copyright (C) 1996-1997 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "quakedef.h"
#include "menu.shared.h"

BOOL	searchComplete = FALSE;
double	searchCompleteTime;


class qmenu_search_t : public qmenu_t
{
public:
	qmenu_search_t (void)
	{
		this->AddOption (new qmenu_banner_t ("gfx/p_multi.lmp"));
		this->AddOption (new qmenu_divider_t ());
		this->Register (m_search);
	}

	void EnterFunc (void)
	{
		this->EnterMenu ();

		slistSilent = TRUE;
		slistLocal = FALSE;
		searchComplete = FALSE;
		NET_Slist_f ();
	}

	BOOL KeyFunc (int key)
	{
		// intercept all keys
		return TRUE;
	}

protected:
	void CustomDraw (void)
	{
		M_DrawCommand (44, "Searching...");

		if (slistInProgress)
		{
			NET_Poll ();
			return;
		}

		if (!searchComplete)
		{
			searchComplete = TRUE;
			searchCompleteTime = realtime;
		}

		if (hostCacheCount)
		{
			menus[m_slist]->EnterFunc ();
			return;
		}

		char *notfound = "No Quake servers found";

		M_PrintWhite (160 - strlen (notfound) * 4, 64, notfound);

		if ((realtime - searchCompleteTime) < 3.0)
			return;

		this->LeaveMenu ();
	}
} menu_search;


